import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'

// 解决报错
// NavigationDuplicated: Avoided redundant navigation to current location
// 原始push方法
const originalPush = VueRouter.prototype.push
// 修改push方法
VueRouter.prototype.push = function(location, onComplete, onAbort) {
  if (onComplete || onAbort) {
    return originalPush.call(this, location, onComplete, onAbort)
  }
  return originalPush.call(this, location).catch(() => {})
}
// 原始replace方法
const originalReplace = VueRouter.prototype.replace
// 修改replace方法
VueRouter.prototype.replace = function(location, onComplete, onAbort) {
  if (onComplete || onAbort) {
    return originalReplace.call(this, location, onComplete, onAbort)
  }
  return originalReplace.call(this, location).catch(() => {})
}

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

export default router
